#include "stdafx.h"
#include "wf_editundo.h"
#include "pf_snapper.h"

/**
 * Constructor.
 *
 * @param undo true for undo and false for redo.
 */
WF_EditUndo::WF_EditUndo(bool undo,
                                     PF_Container& container,
                                     PF_GraphicView& graphicView)
        :PF_ActionInterface("Edit Undo",
                    container, graphicView) {

    this->undo = undo;
}



WF_EditUndo::~WF_EditUndo() {}


QAction* WF_EditUndo::createGUIAction(LX_Define::ActionType type, QObject* parent) {
    QAction* action;
    if (type==LX_Define::ActionEditUndo) {		
		// tr("Undo")
		action = new QAction(tr("&Undo"), parent);
#if QT_VERSION >= 0x040600
                action->setIcon(QIcon::fromTheme("edit-undo", QIcon(":/actions/undo2.png")));
#else
                action->setIcon(QIcon(":/actions/undo2.png"));
#endif
		action->setShortcut(QKeySequence::Undo);
		//action->zetStatusTip(tr("Undoes last action"));
    } else {
		// tr("Redo")
		action = new QAction(tr("&Redo"), parent);
#if QT_VERSION >= 0x040600
                action->setIcon(QIcon::fromTheme("edit-redo", QIcon(":/actions/redo2.png")));
#else
                action->setIcon(QIcon(":/actions/redo2.png"));
#endif
		action->setShortcut(QKeySequence::Redo);
		//action->zetStatusTip(tr("Redoes last action"));
    }

    return action;
}

void WF_EditUndo::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}



void WF_EditUndo::trigger() {
    if (undo) {
        document->undo();
    } else {
        document->redo();
    }

    document->updateInserts();

	graphicView->redraw(LX_Define::RedrawDrawing); 


    finish();
    PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}


// EOF
